package com.pm.controller.official;

import com.pm.common.Response;
import com.pm.common.annotation.CurrentUser;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.official.OfficialScoreStatistics;
import com.pm.entity.po.security.User;
import com.pm.service.official.OfficialScoreStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: pm_info_api
 * @description: 党政一把手打分统计
 * @author: xzj
 * @create: 2020-08-19 18:14
 **/
@Api(tags = "党政一把手打分统计")
@UserLoginToken
@RestController
@RequestMapping("/OfficialScoreStatistics")
public class OfficialScoreStatisticsController {

    @Autowired
    OfficialScoreStatisticsService officialScoreStatisticsService;

    @ApiOperation("新增接口")
    @PostMapping("/add")
    @ResponseBody
    @MyLog(value = "党政一把手打分统计")
    public Response<Integer> add(@RequestBody OfficialScoreStatistics officialScoreStatistics, @CurrentUser User user) {
        Response<Integer> response = null;
        officialScoreStatistics.setAddUser(user.getUserId());
        officialScoreStatistics.setEditUser(user.getUserId());
        Integer result = officialScoreStatisticsService.addOne(officialScoreStatistics);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }

    @ApiOperation("全部列表查询接口")
    @PostMapping("/getList")
    @ResponseBody
    public Response<List<OfficialScoreStatistics>> getList(@RequestBody OfficialScoreStatistics officialScoreStatistics) {
        List<OfficialScoreStatistics> result = officialScoreStatisticsService.getList(officialScoreStatistics);
        Response<List<OfficialScoreStatistics>> res = new Response<List<OfficialScoreStatistics>>(ExpCodeState.query_data_success, result);
        return res;
    }
}
